package tp.badugi.client;

import java.awt.Image;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public class ImageProvider {
	
	private final String folderPath = "/Images/"; 
	
	private final String cardsFolderPath = this.folderPath + "Cards/";

	public Image CLUBS_ACE;
	public Image CLUBS_2;
	public Image CLUBS_3;
	public Image CLUBS_4;
	public Image CLUBS_5;
	public Image CLUBS_6;
	public Image CLUBS_7;
	public Image CLUBS_8;
	public Image CLUBS_9;
	public Image CLUBS_10;
	public Image CLUBS_JACK;
	public Image CLUBS_QUEEN;
	public Image CLUBS_KING;
	       
	public Image DIAMONDS_ACE;
	public Image DIAMONDS_2;
	public Image DIAMONDS_3;
	public Image DIAMONDS_4;
	public Image DIAMONDS_5;
	public Image DIAMONDS_6;
	public Image DIAMONDS_7;
	public Image DIAMONDS_8;
	public Image DIAMONDS_9;
	public Image DIAMONDS_10;
	public Image DIAMONDS_JACK;
	public Image DIAMONDS_QUEEN;
	public Image DIAMONDS_KING;
	       
	public Image HEARTS_ACE;
	public Image HEARTS_2;
	public Image HEARTS_3;
	public Image HEARTS_4;
	public Image HEARTS_5;
	public Image HEARTS_6;
	public Image HEARTS_7;
	public Image HEARTS_8;
	public Image HEARTS_9;
	public Image HEARTS_10;
	public Image HEARTS_JACK;
	public Image HEARTS_QUEEN;
	public Image HEARTS_KING;
	       
	public Image SPADES_ACE;
	public Image SPADES_2;
	public Image SPADES_3;
	public Image SPADES_4;
	public Image SPADES_5;
	public Image SPADES_6;
	public Image SPADES_7;
	public Image SPADES_8;
	public Image SPADES_9;
	public Image SPADES_10;
	public Image SPADES_JACK;
	public Image SPADES_QUEEN;
	public Image SPADES_KING;
	
	public Image CARD_BACK;
	
	//-- Special ERROR_IMAGE
	
	public Image ERROR_IMAGE;
	
	public ImageIcon TOHO;
	
	public ImageProvider() {
		
		try{
			this.ERROR_IMAGE	= ImageIO.read(getClass().getResource(this.folderPath + "ErrorImage.jpg"));
			
			this.TOHO			= new ImageIcon(getClass().getResource(this.folderPath + "Touhou 2.gif"));
	
			CARD_BACK			= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Card Back.jpg"));
			
			this.CLUBS_ACE		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Clubs Ace.jpg"));
			this.CLUBS_2		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Clubs 2.jpg"));
			this.CLUBS_3		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Clubs 3.jpg"));
			this.CLUBS_4		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Clubs 4.jpg"));
			this.CLUBS_5		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Clubs 5.jpg"));
			this.CLUBS_6		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Clubs 6.jpg"));
			this.CLUBS_7		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Clubs 7.jpg"));
			this.CLUBS_8		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Clubs 8.jpg"));
			this.CLUBS_9		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Clubs 9.jpg"));
			this.CLUBS_10		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Clubs 10.jpg"));
			this.CLUBS_JACK		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Clubs Jack.jpg"));
			this.CLUBS_QUEEN	= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Clubs Queen.jpg"));
			this.CLUBS_KING		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Clubs King.jpg"));
			
			this.DIAMONDS_ACE	= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Diamonds Ace.jpg"));
			this.DIAMONDS_2		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Diamonds 2.jpg"));
			this.DIAMONDS_3		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Diamonds 3.jpg"));
			this.DIAMONDS_4		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Diamonds 4.jpg"));
			this.DIAMONDS_5		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Diamonds 5.jpg"));
			this.DIAMONDS_6		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Diamonds 6.jpg"));
			this.DIAMONDS_7		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Diamonds 7.jpg"));
			this.DIAMONDS_8		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Diamonds 8.jpg"));
			this.DIAMONDS_9		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Diamonds 9.jpg"));
			this.DIAMONDS_10	= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Diamonds 10.jpg"));
			this.DIAMONDS_JACK	= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Diamonds Jack.jpg"));
			this.DIAMONDS_QUEEN	= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Diamonds Queen.jpg"));
			this.DIAMONDS_KING	= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Diamonds King.jpg"));
			
			this.HEARTS_ACE		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Hearts Ace.jpg"));
			this.HEARTS_2		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Hearts 2.jpg"));
			this.HEARTS_3		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Hearts 3.jpg"));
			this.HEARTS_4		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Hearts 4.jpg"));
			this.HEARTS_5		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Hearts 5.jpg"));
			this.HEARTS_6		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Hearts 6.jpg"));
			this.HEARTS_7		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Hearts 7.jpg"));
			this.HEARTS_8		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Hearts 8.jpg"));
			this.HEARTS_9		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Hearts 9.jpg"));
			this.HEARTS_10		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Hearts 10.jpg"));
			this.HEARTS_JACK	= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Hearts Jack.jpg"));
			this.HEARTS_QUEEN	= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Hearts Queen.jpg"));
			this.HEARTS_KING	= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Hearts King.jpg"));
			
			this.SPADES_ACE		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Spades Ace.jpg"));
			this.SPADES_2		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Spades 2.jpg"));
			this.SPADES_3		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Spades 3.jpg"));
			this.SPADES_4		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Spades 4.jpg"));
			this.SPADES_5		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Spades 5.jpg"));
			this.SPADES_6		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Spades 6.jpg"));
			this.SPADES_7		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Spades 7.jpg"));
			this.SPADES_8		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Spades 8.jpg"));
			this.SPADES_9		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Spades 9.jpg"));
			this.SPADES_10		= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Spades 10.jpg"));
			this.SPADES_JACK	= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Spades Jack.jpg"));
			this.SPADES_QUEEN	= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Spades Queen.jpg"));
			this.SPADES_KING	= ImageIO.read(getClass().getResource(this.cardsFolderPath + "Spades King.jpg"));
		}
		catch(IOException ex){
			System.out.println(ex.getMessage());
		}
	}
	
	public Image getCardImage(String card){
		
		Image cardImage;
		
		char cardColor;
		char cardValue;
		
		if( card == null || card.length() < 2){
			return CARD_BACK;
		}
		else{
		cardColor = Character.toUpperCase(card.charAt(1));
		cardValue = Character.toUpperCase(card.charAt(0));
		
			switch(cardColor){
				case 'C':
					switch(cardValue){
						case 'A' : cardImage = this.CLUBS_ACE;
							break;
						case '2' : cardImage = this.CLUBS_2;
							break;
						case '3' : cardImage = this.CLUBS_3;
							break;
						case '4' : cardImage = this.CLUBS_4;
							break;
						case '5' : cardImage = this.CLUBS_5;
							break;
						case '6' : cardImage = this.CLUBS_6;
							break;
						case '7' : cardImage = this.CLUBS_7;
							break;
						case '8' : cardImage = this.CLUBS_8;
							break;
						case '9' : cardImage = this.CLUBS_9;
							break;
						case 'T' : cardImage = this.CLUBS_10;
							break;
						case 'J' : cardImage = this.CLUBS_JACK;
							break;
						case 'Q' : cardImage = this.CLUBS_QUEEN;
							break;
						case 'K' : cardImage = this.CLUBS_KING;
							break;
						default	: cardImage = this.ERROR_IMAGE;
							break;
					}
				break;
				
				case 'D':
					switch(cardValue){
						case 'A' : cardImage = this.DIAMONDS_ACE;
							break;
						case '2' : cardImage = this.DIAMONDS_2;
							break;
						case '3' : cardImage = this.DIAMONDS_3;
							break;
						case '4' : cardImage = this.DIAMONDS_4;
							break;
						case '5' : cardImage = this.DIAMONDS_5;
							break;
						case '6' : cardImage = this.DIAMONDS_6;
							break;
						case '7' : cardImage = this.DIAMONDS_7;
							break;
						case '8' : cardImage = this.DIAMONDS_8;
							break;
						case '9' : cardImage = this.DIAMONDS_9;
							break;
						case 'T' : cardImage = this.DIAMONDS_10;
							break;
						case 'J' : cardImage = this.DIAMONDS_JACK;
							break;
						case 'Q' : cardImage = this.DIAMONDS_QUEEN;
							break;
						case 'K' : cardImage = this.DIAMONDS_KING;
							break;
						default	: cardImage = this.ERROR_IMAGE;
							break;
					}
				break;
				
				case 'H':
					switch(cardValue){
						case 'A' : cardImage = this.HEARTS_ACE;
							break;
						case '2' : cardImage = this.HEARTS_2;
							break;
						case '3' : cardImage = this.HEARTS_3;
							break;
						case '4' : cardImage = this.HEARTS_4;
							break;
						case '5' : cardImage = this.HEARTS_5;
							break;
						case '6' : cardImage = this.HEARTS_6;
							break;
						case '7' : cardImage = this.HEARTS_7;
							break;
						case '8' : cardImage = this.HEARTS_8;
							break;
						case '9' : cardImage = this.HEARTS_9;
							break;
						case 'T' : cardImage = this.HEARTS_10;
							break;
						case 'J' : cardImage = this.HEARTS_JACK;
							break;
						case 'Q' : cardImage = this.HEARTS_QUEEN;
							break;
						case 'K' : cardImage = this.HEARTS_KING;
							break;
						default	: cardImage = this.ERROR_IMAGE;
							break;
					}
				break;
				
				case 'S':
					switch(cardValue){
						case 'A' : cardImage = this.SPADES_ACE;
							break;
						case '2' : cardImage = this.SPADES_2;
							break;
						case '3' : cardImage = this.SPADES_3;
							break;
						case '4' : cardImage = this.SPADES_4;
							break;
						case '5' : cardImage = this.SPADES_5;
							break;
						case '6' : cardImage = this.SPADES_6;
							break;
						case '7' : cardImage = this.SPADES_7;
							break;
						case '8' : cardImage = this.SPADES_8;
							break;
						case '9' : cardImage = this.SPADES_9;
							break;
						case 'T' : cardImage = this.SPADES_10;
							break;
						case 'J' : cardImage = this.SPADES_JACK;
							break;
						case 'Q' : cardImage = this.SPADES_QUEEN;
							break;
						case 'K' : cardImage = this.SPADES_KING;
							break;
						default	: cardImage = this.ERROR_IMAGE;
							break;
					}
				break;
				
				default	: cardImage = this.ERROR_IMAGE;
					break;
			}
		}
		
		return cardImage;
	}
}
